package com.taotao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
 * 处理内容表相关的
 * @title ContentController.java
 * <p>description</p>
 * <p>company: www.itheima.com</p>
 * @author ljh 
 * @version 1.0
 */
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.content.service.ContentService;
import com.taotao.pojo.TbContent;
@Controller
public class ContentController {
	@Autowired
	private ContentService contentService;
	
	// url:'/content/query/list',queryParams:{categoryId:0}
	@RequestMapping(value="/content/query/list",method=RequestMethod.GET)
	@ResponseBody
	public List<TbContent> getContentListByCatId(@RequestParam(value="categoryId",defaultValue="0") Long categoryId) {
		return contentService.getContentListByCatId(categoryId);
	}
	
	//	$.post("/content/save",$("#contentAddForm").serialize(), function(data){
	//返回值是JSON
	@RequestMapping(value="/content/save",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult saveContent(TbContent tContent){
		//1.引入服务
		//2.注入服务
		//3.调用
		return contentService.saveContent(tContent);
	}
	
	// $.post("/rest/content/edit",$("#contentEditForm").serialize(), function(data){
	//返回值是JSON
	@RequestMapping(value="/rest/content/edit",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult updateContent(TbContent content) {
		//1.引入服务
		//2.注入服务
		//3.调用
		return contentService.updateContent(content);
	}
	
	// $.post("/content/delete",params, function(data){
	//返回值是JSON
	@RequestMapping(value="/content/delete",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult deleteContent(String ids) {
		//1.引入服务
		//2.注入服务
		//3.调用
		return contentService.deleteContent(ids);
	}
}
